/* Copyright (c) 2016-2020 Enfry Ltd. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of Enfry. 
 * You shall not disclose such Confidential Information
 * and shall use it only in accordance with the terms of the agreements
 * you entered into with Enfry.
 */
package com.enfry.storage;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jweb.framework.core.Context;
import com.jweb.framework.core.CoreException;
import com.jweb.framework.core.CoreRuntimeException;
import com.jweb.framework.core.Interceptor;

public class LogInterceptor implements Interceptor {

    private Logger logger = LoggerFactory.getLogger(getClass());

    public LogInterceptor() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onRequest(Context ctx) throws CoreException, CoreRuntimeException {
        Map<String, Object> map = ctx.getDataMapDirectly();
        if (!map.isEmpty()) {
            logger.debug("----------------------------------------------PARAM----------------------------------------------");
            logger.debug(ctx.getProcessId() + ":" + map.toString());
        } else {
            //logger.debug("前端")
        }
    }

    @Override
    public void onResponse(Context ctx, Throwable arg1) {
        Map<String, Object> map = new HashMap<String, Object>(ctx.getDataMapDirectly());
        if (!map.isEmpty()) {
            logger.debug("----------------------------------------------DATA----------------------------------------------");
            logger.debug(ctx.getProcessId() + ":" + map.toString());
        }
    }

}
